package com.hzsai.mininote.entity;

import com.hzsai.mininote.converter.SexEnumConverter;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * @author hzsai
 * @date 2020/1/7 14:03
 * @usage: 直接对应数据库类
 */
@Data
@Entity(name = "user") // 实体名称
@Table(name = "user") // 对应数据库表名
public class User{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id = null;

    @NotBlank(message = "用户名不能为空")
    @Length(min = 2, max = 30, message = "名字长度错误，需在2~30之间")
    @Column(name = "name")
    private String name = null;

    @Length(max = 255, message = "长度错误，需 < 255字符长度")
    @Column(name = "nickname")
    private String nickname = null;

    @Length(max = 255, message = "长度错误，需 < 255字符长度")
    @Column(name = "avatar")
    private String avatar;

    @Length(max = 255, message = "长度错误，需 < 255字符长度")
    @Column(name = "motto")
    private String motto;

    @Email(message = "邮件格式错误，请重新输入")
    @Column(name = "email")
    private String email = null;

    // 入库sha256值
    @NotBlank(message = "密码不能为空")
    @Length(min = 6, max = 30, message = "密码长度错误，需在6~30之间")
    @Column(name = "password")
    private String password = null;

    @NotNull
    @Column(name = "register_time")
    private LocalDateTime registerTime;

    @Column(name = "last_visit")
    private LocalDateTime lastVisit;

//    @Range(min = 0, max = 3)
    @Convert(converter = SexEnumConverter.class)
    @Column(name = "sex")
    private SexEnum sex = null;
}
